﻿Chenxin.UI.BusinessMarket = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/logic/BusinessMarket.ashx',
    createSearch: function() {
        return new Chenxin.UI.BusinessMarketSearch({
            scope: this
        });
    },
    createGrid: function() {
        _this = this;
        return new Chenxin.UI.JsonGrid({
            createTitleTool: function() {
                return [{
                    text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
                    scope: this,
                    title: '导出全部数据',
                    handler: function(el) {
                        _this.exportAll();
                    }
}];
                },
                actionUrl: this.actionUrl + '?op=getlist',
                pageSize: 100,
                hasPage: true,
                cellBorder: true,
                height: 400,
                autoLoad: false,
                renderTo: 'BusinessMarket_table',
                hasCheckBox: false,
                id: 'searchtable',
                title: '成交行情表',
                scope: this,
                columns: {
                    ContractCode: {
                        width: 150,
                        head: '成交编号',
                        sortable: true
                    },
                    ContractDate: {
                        width: 120,
                        head: '成交日期',
                        sortable: true,
                        renderer: function(val, field, row) {
                            return val.split(' ')[0];
                        }
                    },
                    BusinessType: {
                        width: 100,
                        head: '成交类别',
                        sortable: true,
                        renderer: function(val, field, row) {
                            if (val == 10)
                                return '买卖';
                            else if (val == 20)
                                return '租赁';
                            else if (val == 30)
                                return '零散';
                            else if (val == 40)
                                return '其他';
                            else
                                return '';
                        }
                    },
                    Region: {
                        width: 100,
                        head: '区域',
                        sortable: true
                    },
                    Community: {
                        width: 150,
                        head: '小区名称',
                        sortable: true
                    },
                    HouseAddress: {
                        width: 300,
                        head: '地址',
                        sortable: true
                    },
                    BargainPrice: {
                        width: 100,
                        head: '成交价格',
                        sortable: true
                    },
                    BargainUnitPrice: {
                        width: 100,
                        head: '单价',
                        sortable: true
                    },
                    Area: {
                        width: 100,
                        head: '面积',
                        sortable: true
                    },
                    HouseType: {
                        width: 120,
                        head: '房型',
                        sortable: true
                    },
                    CompleteYear: {
                        width: 120,
                        head: '竣工年份',
                        sortable: true
                    },
                    HouseUse: {
                        width: 120,
                        head: '房屋用途',
                        sortable: true
                    },
                    BuildingType: {
                        width: 120,
                        head: '房屋类型',
                        sortable: true
                    },
                    Fitment: {
                        width: 150,
                        head: '装修情况',
                        sortable: true
                    }
                }
            });
        },
        exportAll: function() {
            _this = this;
            paramStr = this.search.getParamJson();
            paramStr.op = 'exportAll';
            Chenxin.Msg.Waiting.show();
            Chenxin.Fn.exportToExcelByServer(this.actionUrl, paramStr, '导出文件');
            //$.ajax({ url: this.actionUrl, data: paramStr,async:false});
            Chenxin.Msg.Waiting.hide();
        },
        initComponent: function() {
            Chenxin.UI.BusinessMarket.superclass.initComponent.call(this);
        }
    });

/**
*查询面板
*/
Chenxin.UI.BusinessMarketSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'BusinessMarket_search',
    initEvent: function() {
        var _this = this;

        //查询按钮
        $('#btnSreach').click(function() {
            _this.scope.reloadGrid("",0);
        });
        $('#keyword').defText({
            deftxt: '输入地址/小区名称'
        });
        $('#area_start').numberText({
            minValue: 0
        });
        $('#area_end').numberText({
            minValue: 0
        });
        $('#lowprice').numberText({
            minValue: 0
        });
        $('#heightprice').numberText({
            minValue: 0
        });
        $('#area_start').defText({
            deftxt: '起始值'
        });
        $('#area_end').defText({
            deftxt: '结束值'
        });
        $('#lowprice').defText({
            deftxt: '起始值'
        });
        $('#heightprice').defText({
            deftxt: '结束值'
        });
    },
    createComboList: function() {
        var cmbDateType = new Chenxin.UI.Combo({
            containerId: '#datetype',
            name: 'datetype',
            tbxWidth: 55,
            addPleaseSelected: false,
            items: [{ val: 'ContractDate', txt: '成交日期' }, { val: 'ArchivementDate', txt: '业绩归属'}]
        });
        var cmbType = new Chenxin.UI.Combo({
            containerId: '#BusinessType',
            name: 'businesstype',
            tbxWidth: 55,
            items: [{ val: '10', txt: '买卖' }, { val: '20', txt: '租赁' }, { val: '-1', txt: '全部'}]
        });

        var houseuse = new Chenxin.UI.ParameterCombo({
            containerId: '#HouseUse',
            key: 'House.Use',
            autoLoad: true,
            tbxWidth: 60,
            inModelType: 'txt',
            paramType: 'text'
        });
        var buildingtype = new Chenxin.UI.ParameterCombo({
            containerId: '#buildingtype',
            key: 'Building.Type',
            autoLoad: true,
            tbxWidth: 60,
            inModelType: 'txt',
            paramType: 'text'
        });
        var region = new Chenxin.UI.ParameterCombo({
            name: 'region',
            containerId: '#region',
            key: 'System.Region',
            tbxWidth: 60,
            inModelType: 'txt'
        });

        //五级联Combo
        var combl = new Chenxin.UI.StructComboList({
            tbxWidth: 60
        });
        var structs = combl.comboList;
        structs.push(cmbDateType);
        structs.push(cmbType);
        structs.push(houseuse);
        structs.push(buildingtype);
        structs.push(region);
        return structs;
    },
    initComponent: function() {
        Chenxin.UI.BusinessMarketSearch.superclass.initComponent.call(this);
    }
});

$(document).ready(function() {
    this.BusinessMarket = new Chenxin.UI.BusinessMarket();
});